package com.github.tobato.fastdfs.domain;

import org.apache.commons.lang3.Validate;

/**
 * 缩略图配置参数
 *
 * @author tobato
 */
public class DefaultThumbImageConfig implements ThumbImageConfig {

    private int width;

    private int height;

    private Float quality;

//    private static String cachedPrefixName;

    public DefaultThumbImageConfig(int width, int height) {
        this.width = width;
        this.height = height;
        this.quality = 1f;
    }

    public DefaultThumbImageConfig() {
    }

    /**
     * 生成前缀如:_150x150
     */
    @Override
    public String getPrefixName() {
        return "_" + width + "x" + height;
    }

    /**
     * 根据文件名获取缩略图路径
     */
    @Override
    public String getThumbImagePath(String masterFilename) {
        Validate.notBlank(masterFilename, "主文件不能为空");
        StringBuilder buff = new StringBuilder(masterFilename);
        int index = buff.lastIndexOf(".");
        buff.insert(index, getPrefixName());
        return buff.toString();
    }

    public void setWidth(int width) {
        this.width = width;
    }

    public void setHeight(int height) {
        this.height = height;
    }

    public int getWidth() {
        return width;
    }

    public int getHeight() {
        return height;
    }

    @Override
    public Float getQuality() {
        return quality;
    }

    public void setQuality(Float quality) {
        this.quality = quality;
    }
}
